Skip to main content

Overview

Duet uses Cloudflare Workers to provide serverless AI-powered pair programming assistance. The worker routes requests to room-specific DuetAgent Durable Object instances based on room IDs extracted from the URL path.

Worker Architecture

The main worker acts as a router that:
  • Extracts room IDs from incoming request URLs
  • Routes requests to the appropriate DuetAgent Durable Object
  • Handles room cleanup operations

Request Routing

The worker matches URLs against the pattern /api/rooms/{roomId}/{endpoint} using regex:
Source: ~/workspace/source/cf-worker/index.ts:28-42

Supported Endpoints

The worker supports three main endpoints:
  1. POST /api/rooms//message - Send messages to the AI agent
  2. POST /api/rooms//sandbox/exec - Execute commands in the room’s sandbox
  3. DELETE /api/rooms/ - Clean up room resources
Source: ~/workspace/source/cf-worker/index.ts:60-65

Health Check

A simple health check endpoint is available:
Source: ~/workspace/source/cf-worker/index.ts:34-36

DuetAgent Durable Object

The DuetAgent class extends the Agent base class and maintains conversation state for each room. Each room gets its own DuetAgent instance.

State Management

Source: ~/workspace/source/cf-worker/index.ts:18-27

Request Handling

The onRequest method routes incoming requests to appropriate handlers:
Source: ~/workspace/source/cf-worker/index.ts:92-120

Configuration

The worker is configured via wrangler.toml:
Source: ~/workspace/source/cf-worker/wrangler.toml:1-13 The configuration binds:
  • DUET_AGENT - DuetAgent Durable Object instances
  • Sandbox - Sandbox Durable Object instances
  • AI - Cloudflare AI binding for LLM access

Client Integration

The Go backend communicates with the worker using the AI client:
Source: ~/workspace/source/internal/ai/client.go:68-103

Next Steps